﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<script>
    var IsAudit = "@LeSoft.Application.Bussiness.WorkRoleSettingBLL.GetIsAudit(Convert.ToInt32(LeSoft.Application.Code.WorkRoleEnum.SeeRoom1))";
    var IsColse = "@LeSoft.Application.Bussiness.WorkRoleSettingBLL.GetIsAudit(Convert.ToInt32(LeSoft.Application.Code.WorkRoleEnum.SeeRoom2))";
    var keyValue = request('keyValue');
    var Id = "";
    var State = -1, Memo = "", organizeid = "";
    $(function () {
        InitialPage();
    })
    //初始化界面
    function InitialPage() {
        $("#State").ComboBox({
            data: [{ "key": "2", "value": "未完成" }, { "key": "3", "value": "已完成" }, { "key": "4", "value": "已取消" }],
            id: "key",
            text: "value",
            description: "=单据执行状态=",
            height: "150px",
            click: function (e) {
                if (e.attr('data-value') > 2) {
                    $(".BassClass").removeAttr("disabled");
                    $("#lr-state").removeAttr("disabled");
                } else {
                    $(".BassClass").attr("disabled", "disabled");
                    $("#lr-state").attr("disabled", "disabled");
                }
                if (e.attr('data-value') == 4) {
                    $(".BassClass").attr("disabled", "disabled");

                }

            }
        });
        $("#OrganizeId").ComboBoxTree({
            url: "../../BaseManage/Organize/GetTreeJsonById",
            description: "==所属机构==",
            height: "250px",
            click: function (data) {
            }
        });
        if (!!keyValue) {
            $.SetForm({
                url: "../../QualificationManage/SearchRoom/GetBillInfo",
                param: { BillCode: keyValue },
                success: function (data) {
                    Id = data.BillInfo.Id;
                    State = data.BillInfo.State
                    organizeid = data.BillInfo.OrganizeId;
                    $("#OrganizeId").ComboBoxSetValue(organizeid);
                    if (State > 1) {
                        $("#Chk").attr("disabled", "disabled");
                        $("#lr-audit").attr("disabled", "disabled");
                        $("#Unchk").attr("disabled", "disabled");
                        $("#Try").attr("hidden", "hidden");
                        $("#Try1").removeAttr("hidden");
                        $("#Chk").attr("checked", "checked");
                        $(".BassClass1").attr("disabled", "disabled");
                        $(".BassClass").removeAttr("disabled"); 
                        $(".AiditInfo").css({ "backgroundColor": "#FFF29D" });
                        var str = "审核人：" + data.BillInfo.ApprovalMan + "&nbsp;&nbsp;审核日期：" + data.BillInfo.ApprovalTime + "&nbsp;&nbsp;审核说明：" + data.BillInfo.ApprovalDescription;
                        $(".AiditInfo").html(str);
                    }
                    if (State == 0) {
                        $("#Chk").attr("disabled", "disabled");
                        $("#lr-audit").attr("disabled", "disabled");
                        $("#Unchk").attr("disabled", "disabled");
                        $("#Unchk").attr("checked", "checked");
                        $("#Try").removeAttr("hidden");
                        $("#Try1").attr("hidden", "hidden");
                        $("#ApprovalDescription").attr("disabled", "disabled");
                        $("#ApprovalDescription").val(Memo);
                    }
                    if (State === "" || State == 1 || State == 2 || State == 5) { 
                        $(".BassClass").attr("disabled", "disabled");
                        $("#lr-state").attr("disabled", "disabled"); 
                    }
                    if (State == 5 || State == 3) {
                        $("#Unchk").attr("checked", "checked");
                        $("#Try").removeAttr("hidden");
                        $("#Try1").attr("hidden", "hidden");
                        $("#ApprovalDescription").attr("disabled", "disabled");
                        $("#ApprovalDescription").val(Memo);
                        $("#State").attr("disabled", "disabled");
                    }
                    if (State == 3 || State == 4) {
                        $("#Unchk").attr("checked", "checked");
                        $("#Try").removeAttr("hidden");
                        $("#Try1").attr("hidden", "hidden");
                        $("#ApprovalDescription").attr("disabled", "disabled");
                        $("#ApprovalDescription").val(Memo);
                        $("#State").attr("disabled", "disabled");
                        $("#lr-state").attr("disabled", "disabled");
                        $("#RealTime").attr("disabled", "disabled");
                        $("#RealMan").attr("disabled", "disabled");
                        $("#RealPhone").attr("disabled", "disabled");
                        $("#SeeRoomInfo").attr("disabled", "disabled");
                    }
                    $("#State").ComboBoxSetValue(data.BillInfo.State);
                    $("#ZX").SetWebControls(data.BillInfo);
                    if (State > 1) {
                        $("#JH").SetWebControls(data.BillInfo);
                    }
                    $("#Info").SetWebControls(data.RoomInfo);
                    $("#Info").SetWebControls(data.MemberInfo);
                    $("#Info").SetWebControls(data.BillInfo);
                    var State = "";
                    switch (data.RState) {
                        case -1:
                            State = "未知";
                            break;
                        case 0:
                            State = "准备房";
                            break;
                        case 1:
                            State = "待租";
                            break;
                        case 2:
                            State = "已选取";
                            break;
                        case 3:
                            State = "已租";
                            break;
                        case 6:
                            State = "续租中";
                            break;
                        case 6:
                            State = "维修中";

                            break;
                        default:
                            break;
                    }
                    $("#RState").val(State);
                    var MarryInfoText = "";
                    switch (data.MemberInfo.MarryInfo) {
                        case 1:
                        case "1":
                            MarryInfoText = "未婚";
                            break;
                        case 2:
                        case "2":
                            MarryInfoText = "已婚";
                            break;
                        case 3:
                        case "3":
                            MarryInfoText = "离异";
                            break;
                        case 4:
                        case "4":
                            MarryInfoText = "丧偶";
                            break;
                        default: MarryInfoText = data.MemberInfo.MarryInfo;

                    }
                    $("#MarryInfo").val(MarryInfoText);
                    if (data.MemberInfo.Sex == 1 && data.MemberInfo != null) {
                        $("#Sex").val("男");
                    }
                    else if (data.MemberInfo.Sex == 2 && data.MemberInfo != null) {
                        $("#Sex").val("女");
                    }
                    else {
                        $("#Sex").val("");
                    }
                }
            })
        }


    };
    //审批结果
    function Rdo_Sumbit(a) {
        State = a;
        if (a == 1) {
            $("#Try").attr("hidden", "hidden");
            $("#Try1").removeAttr("hidden");
        }
        else {
            $("#Try1").attr("hidden", "hidden");
            $("#Try").removeAttr("hidden");
        }
    };
    //提交
    function btn_Save(a) {//a:1-审批 、2-执行提交
        if (a == 1 && IsAudit == "False") {
            dialogMsg('您不是该业务的处理人！', 0);
            return false;
        }
        if (a == 2 && IsColse =="False") {
            dialogMsg('您不是该业务的处理人！', 0);
            return false;
        }
        if (State === "") {
            dialogMsg('未选择审核结果！', 0);
            return false;
        }
        var postData = $("#Info").GetWebControls(keyValue);
        if (State == 0) {
            postData["State"] = 5;
            postData["ApprovalDescription"] = $("#ApprovalDescription").val();
        }
        if (State == 1) {
            postData["State"] = 2;
            postData["PlanManId"] = $("#RealManId").val();
            postData["PlanMan"] = $("#PlanMan").val();
            postData["PlanPhone"] = $("#PlanPhone").val();
            postData["PlanTime"] = $("#PlanTime").val();
        }
        if (a == 2) {
            if ($("#State").attr('data-value') == 3) {
                if (!$('#ZX').Validform()) {
                    return false;
                }
            }
            postData["State"] = $("#State").attr("data-value");
            postData["RealManId"] = $("#RealManId").val();
            postData["RealMan"] = $("#RealMan").val();
            postData["RealPhone"] = $("#RealPhone").val();
            postData["SeeRoomInfo"] = $("#SeeRoomInfo").val();
            postData["RealTime"] = $("#RealTime").val();
        }
        postData["Id"] = Id;
        $.ConfirmAjax({
            msg: "注：您确认要进行此操作吗？",
            url: "../../QualificationManage/SearchRoom/SaveForm?keyValue=" + Id,
            param: postData,
            loading: "正在保存数据...",
            success: function () {
                $.currentIframe().$("#gridTable").resetSelection();
                $.currentIframe().$("#gridTable").trigger("reloadGrid");
                dialogClose();
            }
        });

    };
    //带看人词典
    function GetMan(Type) {
        var options = {};
        switch (Type) {
            case 1:
                options["type"] = 3;
                options["data"] = [{ "id": "PlanMan" }, { "id": "PlanManId" }];
                options["organizeid"] = '@LeSoft.Application.Code.OperatorProvider.Provider.Current().CompanyId';
                break;
            case 2:
                options["type"] = 3;
                options["data"] = [{ "id": "RealMan" }, { "id": "RealManId" }, { "id": "RealPhone" }];
                options["organizeid"] = '@LeSoft.Application.Code.OperatorProvider.Provider.Current().CompanyId';
                break;
            default:

        }
        DataItemClick(JSON.stringify(options));

    };
</script>
<style>
    .form {
        width: 90%;
        margin-left: 5%;
    }

    #Info td {
        border: 1px solid #ccc;
        height: 40px;
    }

    .cs_1 {
        border: none;
    }

    .cs2 {
        border: 1px solid #ccc;
        height: 40px;
        background-color: #DDF0ED;
    }

    #OrganizeId div {
        border: none;
    }
</style>
<div style="margin-top: 20px; ">
    <table class="form" id="Info">
        <tr>
            <td class="formTitle cs2">所属机构</td>
            <td class="formValue" colspan="4"> <div id="OrganizeId" type="selectTree" readonly class="ui-select cs_1"></div> </td>
            <td class="formTitle cs2">单据编号</td>
            <td class="formValue" colspan="4"><input class="form-control cs_1" readonly id="BillCode" type="text" /></td>
            <td class="formTitle cs2">单据日期</td>
            <td class="formValue" colspan="2"><input class="form-control cs_1" readonly id="Date" type="text" /></td>
        </tr>
        <tr>
            <td class="formTitle cs2">看房地址</td>
            <td class="formValue" colspan="9"><input class="form-control cs_1" readonly id="AllName" type="text" /></td>
            <td class="formTitle cs2">房间状态</td>
            <td class="formValue" colspan="2"> <input class="form-control cs_1" readonly id="RState" type="text" /></td>
        </tr>
        <tr>
            <td class="formTitle cs2">姓名</td>
            <td class="formValue" colspan="2"><input class="form-control cs_1" readonly id="Name" type="text" /></td>
            <td class="formTitle cs2">身份证号</td>
            <td class="formValue" colspan="3"><input class="form-control cs_1" readonly id="IDCard" type="text" /></td>
            <td class="formTitle cs2">性别</td>
            <td class="formValue" colspan="2"><input class="form-control cs_1" readonly id="Sex" type="text" /></td>
            <td class="formTitle cs2">民族</td>
            <td class="formValue" colspan="2"><input class="form-control cs_1" readonly id="Nation" type="text" /></td>
        </tr>
        <tr>
            <td class="formTitle cs2">文化程度</td>
            <td class="formValue" colspan="2"><input class="form-control cs_1" readonly id="Cultural" type="text" /></td>
            <td class="formTitle cs2">手机号码</td>
            <td class="formValue" colspan="3"><input class="form-control cs_1" readonly id="Phone" type="text" /></td>
            <td class="formTitle cs2">固定电话</td>
            <td class="formValue" colspan="2"><input class="form-control cs_1" readonly id="PhoneNum" type="text" /></td>
            <td class="formTitle cs2">婚姻状况</td>
            <td class="formValue" colspan="2"><input class="form-control cs_1" readonly id="MarryInfo" type="text" /></td>
        </tr>
        <tr>
            <td class="formTitle cs2">期望看房时间</td>
            <td class="formValue" colspan="12"><input class="form-control cs_1" readonly id="ExpectTime" type="text" /></td>
        </tr>
        <tr>
            <td class="formTitle cs2">其他说明</td>
            <td class="formValue" colspan="12"><textarea class="form-control cs_1" readonly id="Description" style="height:50px;"></textarea></td>
        </tr> 
    </table>
    <table class="form" id="JH">
        <td colspan="9"><div class="AiditInfo" style="line-height:20px; height:25px;"></div></td>
        <tr style=" height: 20px; border-bottom: 1px dashed #cecece;"><td colspan="9"></td> </tr>
        <tr style="height:20px;"></tr>
        <tr>
            <td class="formTitle ">审批结果</td>
            <td class="formValue"><input id="Chk" name="Sumbit" type="radio" onchange="Rdo_Sumbit(1)" value="1" />同意</td>
            <td class="formValue"><input id="Unchk" name="Sumbit" type="radio" onchange="Rdo_Sumbit(0)" value="0" />不同意</td>
            <td colspan="6"></td>
        </tr>
        <tr id="Try1">
            <td class="formTitle">计划看房时间</td>
            <td class="formValue" colspan="2"><input id="PlanTime" type="text" class="form-control input-wdatepicker BassClass1 " placeholder="请输入计划带看时间" value="@LeSoft.Util.Time.GetToday("yyyy-MM-dd HH:mm:ss")" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd HH:mm:ss' })" /></td>
            <td class="formTitle">预约带看人</td>
            <td class="formValue" colspan="2">
                <div class="input-group" style="width: 100%;">
                    <input id="PlanManId" class="form-control" type="hidden" value="@ViewBag.ManId" />
                    <input id="PlanMan" type="text" class="form-control  BassClass1" value="@ViewBag.Man" isvalid="yes" checkexpession="IsScript" />
                    <span class="input-group-btn">
                        <a onclick="GetMan(1);" class="form-control BassClass1 " style="cursor: pointer "><i class="fa fa fa-book BassClass1" style=" font-size: 20px; padding-right: 5px; padding-top: 5px; color: gray"></i></a>
                    </span>
                </div>
            </td>
            <td class="formTitle">带看人联系方式</td>
            <td class="formValue" colspan="2"><input class="form-control BassClass1" id="PlanPhone" type="text" value="@ViewBag.Phone" isvalid="yes" checkexpession="IsScript" /></td>

        </tr>
        <tr id="Try">
            <td class="formTitle">不同意原因</td>
            <td class="formValue" colspan="8"><textarea class="form-control" id="ApprovalDescription" style="height:50px;" isvalid="yes" checkexpession="IsScript"></textarea></td>
        </tr>

        <tr style="height:20px;"></tr>
        <tr>
            <td colspan="9" style="text-align:center;"><a id="lr-audit" class="btn btn-success " style="background-color: #169BD5; width:200px;" onclick="btn_Save(1); ">提交</a></td>
        </tr>
        <tr style=" height: 20px; border-bottom: 1px dashed #cecece;"><td colspan="9"></td> </tr>
        <tr style="height:20px;"></tr>
    </table>
    <table class="form" id="ZX">
        <tr>
            <td class="formTitle">执行状态</td>

            <td class="formValue" colspan="2"><div id="State" type="select" isvalid="yes" checkexpession="NotNull" class="ui-select  "></div></td>
        </tr>

        <tr>
            <td class="formTitle">实际看房时间</td>
            <td class="formValue" colspan="2"><input id="RealTime" isvalid="yes" checkexpession="NotNull" type="text" class="form-control input-wdatepicker  BassClass " placeholder="请输入实际带看时间" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd HH:mm:ss' })" /></td>
            <td class="formTitle">实际带看人</td>
            <td class="formValue" colspan="2">
                <div class="input-group" style="width: 100%;">
                    <input id="RealManId" class="form-control" type="hidden" />
                    <input id="RealMan" type="text" isvalid="yes" checkexpession="NotNull" class="form-control BassClass " />
                    <span class="input-group-btn">
                        <a onclick="GetMan(2);" class="form-control BassClass" style="cursor: pointer "><i class="fa fa fa-book BassClass" style=" font-size: 20px; padding-right: 5px;padding-top:5px;  color: gray"></i></a>
                    </span>
                </div>
            </td>

            <td class="formTitle">带看人联系方式</td>
            <td class="formValue" colspan="2"><input class="form-control BassClass" isvalid="yes" checkexpession="NotNull" id="RealPhone" type="text" /></td>
        </tr>
        <tr>
            <td class="formTitle">看房情况说明</td>
            <td class="formValue" colspan="8"><textarea class="form-control BassClass" id="SeeRoomInfo" style="height:50px;" isvalid="yes" checkexpession="IsScript"></textarea></td>
        </tr>
        <tr style="height:20px;"></tr>
        <tr>
            <td colspan="9" style="text-align:center;"><a id="lr-state" class="btn btn-success " style="background-color: #169BD5; width:200px;" onclick="btn_Save(2); ">提交</a></td>
        </tr>

    </table>

</div>